 
package ibms_rcp.task.parts;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

public class AddPart {
	//名称
	private Text nameText;
	//所属部门
	private ComboViewer depComboViewer;
	private Combo depCombo;
	//工作描述
	private Text descriptionText;
	//考核标准
	private Text assessText;
	//提交
	private Button okButton;
	//清空
	private Button clearButton;
	
	@Inject
	public AddPart(Composite parent) {
		//TODO Your code here
	}
	
	@PostConstruct
	public void postConstruct(final Composite parent) {
		GridLayout layout = new GridLayout(1, false);
		layout.marginWidth = 10;
		layout.marginHeight = 10;
		parent.setLayout(layout);
		
		Label title = new Label(parent, SWT.NONE);
		title.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD));
		title.setText("新增工作");
		
		Composite infoComposite = new Composite(parent, SWT.NONE);
		infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		infoComposite.setLayout(new GridLayout(3, false));
		
		//名称
		Label nameLabel = new Label(infoComposite, SWT.RIGHT);
		nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		nameLabel.setText("工作名称：");
		nameText = new Text(infoComposite, SWT.BORDER);
		nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(infoComposite, SWT.NONE);
		
		//所属部门
		Label depLabel = new Label(infoComposite, SWT.RIGHT);
		depLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		depLabel.setText("所属部门：");
		depComboViewer = new ComboViewer(infoComposite, SWT.READ_ONLY);
		depCombo = depComboViewer.getCombo();
		depCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		depComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		depComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到部门text
//				if (element instanceof Building) {
//					Building building = (Building) element;
//					return building.getEms_name();
//				}
				return super.getText(element);
			}
		});
		// TODO 获取部门数据
		new Label(infoComposite, SWT.NONE);
//		List<Building> buildings = EstateManager.getBuildings();
//		buildingComboViewer.setInput(buildings);
//
//		buildingComboViewer
//				.addSelectionChangedListener(new ISelectionChangedListener() {
//					@Override
//					public void selectionChanged(SelectionChangedEvent event) {
//						IStructuredSelection selection = (IStructuredSelection) event
//								.getSelection();
//						long buildingId = ((Building) selection
//								.getFirstElement()).getId();
//						// 获取楼层数据
//						List<Floor> floors = EstateManager
//								.getFloorsByBuilding(buildingId);
//						floorComboViewer.setInput(floors);
//					}
//				});
		
		//工作描述
		Label descriptionLabel = new Label(infoComposite, SWT.RIGHT);
		descriptionLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		descriptionLabel.setText("工作描述：");
		descriptionText = new Text(infoComposite, SWT.BORDER);
		descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(infoComposite, SWT.NONE);
		
		//考核标准
		Label assessLabel = new Label(infoComposite, SWT.RIGHT);
		assessLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		assessLabel.setText("工作描述：");
		assessText = new Text(infoComposite, SWT.BORDER);
		assessText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(infoComposite, SWT.NONE);
		
		Composite btnComposite = new Composite(parent, SWT.NONE);
		btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		btnComposite.setLayout(new GridLayout(2, false));
		
		//提交按钮
		okButton = new Button(btnComposite, SWT.NONE);
		okButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		okButton.setText("提交");
		
		//清空按钮
		clearButton = new Button(btnComposite, SWT.NONE);
		clearButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		clearButton.setText("清空");
	}
	
	
	@PreDestroy
	public void preDestroy() {
		//TODO Your code here
	}
	
	
	
}